package com.compass.doctor.ui.mine

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.compass.doctor.R
import com.compass.doctor.base.BaseVBActivity
import com.compass.doctor.databinding.ActivityHospitalizedDetailsBinding
import com.compass.doctor.ui.mine.adapter.HospitalizedItemAdapter
import com.compass.doctor.ui.mine.viewmodel.MineViewModel

import com.compass.framework.constant.KEY_HOSPITALIZED_ID
import com.compass.framework.decoration.NormalItemDecoration
import com.compass.framework.model.MessageBody
import com.compass.framework.utils.BigDecimalUtils
import com.compass.framework.utils.dpToPx
import com.compass.framework.utils.getColorFromResource

/**
 * Description： 住院证详情
 * Date:2024/3/21 10:05
 */
class HospitalizedDetailsActivity : BaseVBActivity<ActivityHospitalizedDetailsBinding>() {


    companion object {
        fun start(context: Context,hospitalizedId:String?) {
            val intent = Intent(context, HospitalizedDetailsActivity::class.java)
            intent.putExtra(KEY_HOSPITALIZED_ID,hospitalizedId)
            context.startActivity(intent)
        }
    }
    private val mineViewModel: MineViewModel by viewModels()
    private var hospitalizedId:String?=null
    private lateinit var mAdapter: HospitalizedItemAdapter

    private var  itemList:ArrayList<MessageBody> = ArrayList()
    override fun initView(savedInstanceState: Bundle?) {
        hospitalizedId=intent.getStringExtra(KEY_HOSPITALIZED_ID)
        mAdapter= HospitalizedItemAdapter()
        mBinding.rcyInfo.apply {
            layoutManager = LinearLayoutManager(context)
            adapter = mAdapter

        }



    }

    override fun initData() {
        showLoading()
        hospitalizedId?.let {  mineViewModel.getHospitalizedDetails(it) }

        mineViewModel.hospitalizedDetailsLiveData.observe(this){
            dismissLoading()
            it?.let { details ->
                itemList.add(MessageBody("姓名",details.patientName))
                itemList.add(MessageBody("性别",details.getSexString()))
                itemList.add(MessageBody("年龄",details.patientAge))
                itemList.add(MessageBody("身份证号",details.idNumber))
                itemList.add(MessageBody("患者ID",details.hisCode))
                itemList.add(MessageBody("临床诊断",details.diagnosisName))
                itemList.add(MessageBody("联系电话",details.mobile))
                itemList.add(MessageBody("家庭地址",details.getAddressString()))
                itemList.add(MessageBody("预交费用", "￥${BigDecimalUtils.divide(details.advancePrice)}"))
                itemList.add(MessageBody("入院科室",details.departmentName))
                itemList.add(MessageBody("病房",details.inpatientWardName))
                itemList.add(MessageBody("开单医生",details.doctorName))
                itemList.add(MessageBody("入院情况",details.conditionText))
                itemList.add(MessageBody("备注信息",details.getRemarkString()))
                mAdapter.setData(itemList)

            }


        }


    }





}